package demo16_volatile;

/**
 * @author kunkun
 * @className Test
 * @Description ...
 * @date 2025/3/7 20:51
 */
public class Test {
    public static int countSwaps(String s) {
        int count0 = 0;
        int count1 = 0;

        // 统计字符串中 0 和 1 的数量
        for (char c : s.toCharArray()) {
            if (c == '0') {
                count0++;
            } else if (c == '1') {
                count1++;
            }
        }

        // 总的交换次数为 count0 * count1
        return count0 * count1;
    }

    public static void main(String[] args) {
        String s = "1100";
        System.out.println("Total swaps: " + countSwaps(s)); // 输出 4
    }
}
